<template>
	<uni-modal class="all">
		<view class="uni-mask"></view>
		<view class="uni-modal">
			<view class="row b-b">
				<text style="font-weight: 600;">物流信息</text>
				<view class="cu-form-group margin-top-bj">
					<view class="title">是否自提</view>
					<switch @change="switchChange" :class="fh.zt == 1?'checked':''" :checked="fh.zt == 1"></switch>
				</view>
				<view v-show="fh.zt == 0">
					<view class="cu-form-group area">
						<!-- <view class="click"></view> -->
		<!-- 				<view class="title">快递公司</view>
						<input type="text" :value="fh.kd" placeholder="选择快递公司" disabled /> -->
					
						<view class="title">快递公司</view>
						<picker @change="PickerChange" :value="fh.kd" :range="list">
							<view class="picker">
								{{fh.kd == ''?'请选择快递公司':fh.kd}}
							</view>
						</picker>
						
					</view>
					<view class="cu-form-group" style="position: relative;">				
						<view class="title">发货单号</view>
						<input type="text" placeholder="单号" v-model="fh.number"></input>
						<text class="wlIcon-saoyisao sys" @click="onWLDHScanClick"></text>
					</view>
					
					<view class="cu-list menu solid-bottom">
						<view class="cu-item" style="min-height:150rpx;" @tap="uploadImages">
							<view class="title">
								<text style="font-size: 30rpx;">发货单拍照</text>
							</view>
							<view class="action">
								<view class="cu-avatar lg" :style="{backgroundImage: fh.images?'url('+ $wanlshop.oss(fh.images, 52, 52, 2, 'avatar') +')':'url('+'/static/images/find/add.png'+')'}" ></view>
							</view>
						</view>
					</view>			
					
				</view>
				
	
				<button v-show="fh.zt == 1"  style="background-color: #64AA58;height: 90rpx;line-height: 90rpx;color: white;margin: 30px 0;" @tap="scanCode" class="iconfont iconsaomiao">扫二维码核销</button>
				
				<button    v-if="loading"  style="background-color: #64AA58;height: 90rpx;line-height: 90rpx;color: white;" class="iconfont iconsaomiao">提交中...</button>
				<button v-else style="background-color: #64AA58;height: 90rpx;line-height: 90rpx;color: white;" @tap="confirmDate" class="iconfont iconsaomiao">{{text}}</button>
			</view>


			<text class="wlIcon-shanchu2 tss" style="position: fixed;top: 3px;right: 3px;color: black;font-size: 18px;" @tap="concel1"></text>			
			
		</view>		
	</uni-modal>
   
</template>

<script>
	export default {
		name:"nxc-show",
		props: {		
			kds: {
				type: Array,
				default: []
			},
			fhid:{
				type:Number,
				default:0
			},
			list:{
				type:Array,
				default:[]
			}		
		},
		data() {
			return {
			  wlNo:'',
			  fh:{
				  id:this.fhid,
				  zt:0,
				  kd:'',
				  code:'',
				  number:'',
				  images:''				 
			  },			 
			  text:'发货单拍照',
			  loading:false
			};
		},
		methods:{
			concel1(){
				console.log(11);
				this.$emit("close",'closesheet2');				
			},
			onWLDHScanClick() {
				let that = this;
				console.log("onScanClick");
				// 调起条码扫描
				uni.scanCode({
					scanType: ['barCode'],
					success: function(res) {					
						that.fh.number = res.result;
					}
				});
			},
			switchChange(e) {
				if (e.detail.value) {
					this.fh.zt = 1;
					this.text = '人工核销';
				} else {
					this.fh.zt = 0;
					this.text = '确认';
				}
			},
			uploadImages(){				
				uni.chooseImage({
					count: 1, // 默认9
					sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: res => {
						// 设置url的值，显示控件
						let tempurl = res.tempFilePaths[0];
						console.log(tempurl);
						// 上传图片
						uni.request({
							url: '/wanlshop/common/uploadData',
							success: updata => {
								uni.uploadFile({
									url: updata.data.uploadurl,
									filePath: tempurl,
									name: 'file',
									formData: updata.data.storage == 'local' ? null : updata.data.multipart,
									success: res => {
										this.fh.images = JSON.parse(res.data).data.fullurl;
									},
									fail: error =>{
										this.$wanlshop.msg(JSON.parse(error.data).msg);
									}
								});
							}
						});
					}
				});
				
			},
			// showKds() {
				
				 //  uni.showActionSheet({				
					// itemList: list,
					// success: (res) => {							  
					// 	 this.fh.kd = this.kds[res.tapIndex].name;		
					// 	 this.fh.code = this.kds[res.tapIndex].code;	
					// },
					// fail: (err) => {
					//   console.log(err);
					// }
				 //  });
			// },
			PickerChange(e) {				
				this.fh.kd = this.kds[e.detail.value].name;
				this.fh.code = this.kds[e.detail.value].code;	
			},
			confirmDate(){
				
				let data = this.fh;
				if (data.zt == 0 && data.number == '') {
					this.$wanlshop.msg('请填写快递单号');
					return;
				}
				let number_ = /^[A-Za-z0-9]{6,40}$/;
				if(data.zt == 0 && !number_.test(data.number)){
					console.log(data.number);
					this.$wanlshop.msg('请输入正确的快递单号');
					return;
				}
				this.loading = true;
				uni.request({					
					url: '/wanlshop/ddp/addkd',
					data: data,
					method:'POST',
					success: res => {
						this.loading = false;
						this.$emit("close",'closesheet3');	
					}
				});
			},
			// 一下扫码
			scanCode() {
				if(!this.$store.state.user.isLogin){
					this.$wanlshop.to('/pages/user/auth/auth');
					return
				}
				
				// #ifndef H5 
				uni.scanCode({
					success: res => {
						let QRcode = res.result;
						let sign = QRcode.substr(0,5);
						if(sign == 'DDGTH'){
							console.log(QRcode);
							let text = QRcode.substr(5);
							console.log(text);
							text = text.replace(/\%2B/g,'+');
							console.log(text);
							text = this.$wanlshop.decrypt(text);
							console.log(text);
						    this.$emit("close",'closesheet2');	
							this.$wanlshop.to('/pages/user2/partner/takeconfirm?text='+text);
						}else{
							this.$wanlshop.msg('未知的二维码！');
						}
						
						 
					}
				});
				// #endif
				// #ifdef H5
				this.$wanlshop.msg('暂不支持H5扫码');
				// #endif
			}

		}
	}
</script>

<style>
	.all{
		position: fixed;
		  top: 0;
		  right: 0;
		  bottom: 0;
		  left: 0;
		  z-index: 999;
		  display: block;
		  box-sizing: border-box;
		  background: rgba(0,0,0,.5);
	}
	.uni-mask{
		position: fixed;
		  z-index: 999;
		  top: 0;
		  right: 0;
		  left: 0;
		  bottom: 0;		
	}
	
	.uni-modal{	
		padding: 50rpx;
		color:black;
		background-color: white;
		position: fixed;
		z-index: 999;
		width: 700rpx;
		height: 780rpx;
		max-width: 700rpx;
		top: 50%;
		left: 50%;
		-webkit-transform: translate(-50%,-50%);
		transform: translate(-50%,-50%);		
		text-align: center;
		border-radius: 3px;
	}
	.uni-modal__hd{
		padding: 1.3em 1.6em 1.3em;
	}
    .uni-modal__bd{
		font-size: 32rpx;
		color:white;
		padding: 1em 1.6em .3em;
		
		  min-height: 40px;
		  font-size: 15px;
		  line-height: 1.4;
		 
		  max-height: 400px;
		  overflow-x: hidden;
		  overflow-y: auto;
	}

	.cu-form-group {
		padding: 0 25rpx;
	}
	/* 1.1.5升级 */
	.cu-form-group.area{
		position: relative;
	}
	.cu-form-group.area .click{
		position: absolute;
		z-index: 99;
		right: 0;
		left: 0;
		top: 0;
		bottom: 0;
	}
	.lg{
		background-color: #D6D1D1;
	}
    .click{
		position: absolute;
		  z-index: 99;
		  right: 0;
		  left: 0;
		  top: 0;
		  bottom: 0;
	}

</style>